package com.chixing.controller;


import com.chixing.entity.Users;
import com.chixing.service.IUsersService;
import com.chixing.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-09-30
 */
@CrossOrigin
@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private IUsersService usersService;

    @PostMapping("login")
    public Result login(@RequestBody Users users){
        return usersService.login(users.getUserName(),users.getPassword());
    }

    @GetMapping("logout/{id}")
    public Result logout(@PathVariable("id") Integer userId){
        return usersService.logout(userId);
    }


    /**
     * 用户注册接口
     * @param users 包含用户名、密码、手机号等信息的用户对象
     * @return 注册结果
     */
    @PostMapping("regist")
    public Result regist(@RequestBody Users users){
        return usersService.regist(users);
    }
}
